-- card: 4707 from stack: in.5 -- bmap block id: 4979 -- flags: 0000 -- background id: 3858 -- name: VolumeIsLocked ----- HyperTalk script ----- on hideObjects hide cd btn "Try It!" end hideObjects on showObjects show cd btn "Try It!" end showObjects -- part 1 (button) -- low flags: 00 -- high flags: A002 -- rect: left=82 top=185 right=219 bottom=175 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp global errGlobal put VolumePath() into diskToCheck if diskToCheck = "" then exit mouseUp put VolumeIsLocked(diskToCheck,"noDialog:errGlobal") into lockedState if errGlobal ≠ empty then answer "Error:" && errGlobal put empty into errGlobal else if lockedState = "True" then put "is" into verb else put "is not" into verb answer "The disk “" & diskToCheck & "”" && verb && "locked" end if end mouseUp -- part contents for background part 38 ----- text ----- 48/50 -- part contents for background part 20 ----- text ----- An XFCN which reports whether or not the specified volume is locked. Calling syntax : VolumeIsLocked(volName,<"noDialog:"errorGlobal>) VOLNAME: the volume to check. -- part contents for background part 42 ----- text ----- { VolumeIsLocked(VolName «,“noDialog:”errorGlobal») } { XCMD to test for a removable disk } {} { brought to you by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356 } {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to:} {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by Eric Carlson } { AppleLink: cyNic } { modification history } { Date Initials Comments } { ---- ------ ------------------------------------------------------ } { 3/1/90 ec first written } { 3/10/90 ec changed so reports volume as locked if "driver needs a call"} {} unit DiskIsLocked; interface uses hyperXCmd; procedure MAIN (paramPtr: XCmdPtr); implementation procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, ''); { return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end; { procedure } function AskedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyrightMsg: Str255): boolean; { check to see if the user sent a '?' or a '!' as } { the only parameter. if so we will respond with } { the calling syntax or the copyright/version info } { for this external } {} var firstStr: str255; begin askedForHelp := false; if paramPtr^.paramCount = 1 then begin ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr); { what is the first param? } if firstStr = '?' then begin reportToUser(paramPtr, syntaxMsg); askedForHelp := true end { asked for help } else if firstStr = '!' then begin reportToUser(paramPtr, copyRightMsg); askedForHelp := true end; { asked for copyright info } end; { one parameter passed } end; { function } function NumberToString (paramPtr: XCmdPtr; num: LONGINT): Str255; { use the toolbox call rather than HC's } var tempStr: str255; begin NumToString(num, tempStr); NumberToString := tempStr; end; procedure ReportVolError (paramPtr: XCmdPtr; errorNum: integer); var errMsg, tempName: str255; begin sysbeep(40); case errorNum of { what caused the problem? } bdNamErr: errMsg := 'Bad volume name.'; extFSErr: errMsg := 'External file system.'; ioErr: errMsg := 'I/O Error.'; nsDrvErr: errMsg := 'No such drive.'; nsvErr: errMsg := 'No such volume.'; paramErr: errMsg := 'No default volume.'; otherwise errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum)); end; { case } errMsg := concat('Sorry, ', errMsg); reportToUser(paramPtr, errMsg); { return the error message } end; { function } function validVolumeName (volumeName: str255): str255; { a volume name must have one (and only one) colon in it, as } { the last character } begin if pos(':', volumeName) = 0 then validVolumeName := concat(volumeName, ':') else validVolumeName := copy(volumeName, 1, pos(':', volumeName)); end; function DriveLocked (aDQEPtr: DrvQElPtr): boolean; { the long proceeding each element in the drive que contains a flag } { in bit 7 of byte 0 which = 1 if volume is locked, 0 if disk is } { unlocked drive, and 8 if a non removable disk is in the drive (IM } { IV-181) } { 6:17 PM 3/1/90 ec } var flagsPtr: ^longint; begin {subtract 4 from the DrvQE1Ptr to grab the long there } flagsPtr := pointer(ord4(aDQEPtr) - 4); DriveLocked := (BAND(BSR(flagsPtr^, 24), 1) = 1); end; function DriveNumToQueElement (driveNum: integer): DrvQElPtr; { given a drive number, return a drive que pointer for that drive } { 12:32 PM 3/1/90 ec } var aQueElement: DrvQElPtr; headPtr: QHdrPtr; begin headPtr := GetDrvQHdr; { grab the drive que header } if headPtr <> nil then begin aQueElement := DrvQElPtr(headPtr^.qHead); while (aQueElement^.dQDrive <> driveNum) and (aQueElement <> nil) do aQueElement := DrvQElPtr(aQueElement^.qLink); DriveNumToQueElement := aQueElement; end else DriveNumToQueElement := nil; end; procedure VolumeIsLocked (paramPtr: XCmdPtr); var volToCheck, tempVar: str255; PB: HParamBlockRec; errorCode: OSErr; begin if AskedForHelp(paramPtr, 'VolumeIsLocked(volumeName, «“noDialog:”errorGlobal»)', '© 1990 Apple Computer, Inc., v1.0 by Eric Carlson') then exit(VolumeIsLocked); if paramPtr^.paramCount = 0 then begin ReportToUser(paramPtr, 'Volume name expected.'); exit(VolumeIsLocked); end else ZeroToPas(paramPtr, paramPtr^.Params[1]^, volToCheck); volToCheck := validVolumeName(volToCheck); { make sure the volume name is correct } { initialize parameter block. Since volToCheck is a full pathname, no other field is needed} zeroBytes(paramPtr, @PB, sizeOf(PB)); PB.ioNamePtr := @volToCheck; PB.ioVolIndex := -1; { use name ONLY } errorCode := PBHGetVInfo(@PB, false); if errorCode <> noErr then begin reportVolError(paramPtr, errorCode); exit(VolumeIsLocked); end; if DriveLocked(DriveNumToQueElement(PB.ioVDrvInfo)) then { is it locked?? } tempVar := 'True' else tempVar := 'False'; ParamPtr^.returnValue := PasToZero(paramPtr, tempVar); end; { procedure VolumeIsLocked} procedure MAIN (paramPtr: XCmdPtr); begin VolumeIsLocked(paramPtr); end; end. { unit DiskIsLocked}